package com.maybach.core.ao.impl;

import com.maybach.common.model.ImportModuleDO;
import com.maybach.common.query.ImportModuleQuery;
import com.maybach.core.ao.ImportModuleAO;
import com.maybach.core.form.product.ModuleQueryForm;
import com.maybach.core.manager.ImportModuleManager;
import com.maybach.util.AssertUtil;
import com.maybach.util.query.support.PageResult;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by pyshift on 16/3/16.
 */
@Component
public class ImportModuleAOImpl implements ImportModuleAO {

    @Autowired
    private ImportModuleManager importModuleManager;

    @Override
    public PageResult<ImportModuleDO> queryImportModule(ModuleQueryForm queryForm) {
        ImportModuleQuery query = this.assemblyQuery(queryForm);
        return importModuleManager.selectByQueryWithPage(query);
    }

    protected ImportModuleQuery assemblyQuery(ModuleQueryForm queryForm) {
        AssertUtil.notNull(queryForm, "queryForm");
        ImportModuleQuery importQuery = new ImportModuleQuery();
        ImportModuleQuery.Criteria criteria = importQuery.or();
        importQuery.setPageNo(queryForm.getPageNo());
        importQuery.setPageSize(queryForm.getPageSize());
        if (StringUtils.isNotBlank(queryForm.getMobile())) {
            criteria.andMobileLike("%" + queryForm.getMobile() + "%");
        }
        if (StringUtils.isNotBlank(queryForm.getCompanyName())) {
            criteria.andCompanyNameLike("%" + queryForm.getCompanyName() + "%");
        }
        return importQuery;
    }
}
